package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.StudentReadSchool;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.views.ScoreDataDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 学员在读公立学校 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-10-21
 */
public interface StudentReadSchoolMapper extends BaseMapper<StudentReadSchool> {
    @Select("SELECT t2.`name` FROM student_read_school AS t1 LEFT JOIN student_at_school AS t2 ON t1.reading_school_id = t2.id WHERE student_id = ${studentId}")
    List<String> readSchoolNameByStudentIdList(@Param("studentId") Long studentId);

    @Select("SELECT t2.`name` FROM student_read_school AS t1 LEFT JOIN student_at_school AS t2 ON t1.reading_school_id = t2.id WHERE student_id = ${studentId}")
    public String readSchoolNameByStudentId(@Param("studentId") Long studentId);

//    @Select("<script>" +
//            "SELECT t2.`name` " +
//            "FROM student_read_school AS t1 " +
//            "LEFT JOIN student_at_school AS t2 ON t1.reading_school_id = t2.id " +
//            "WHERE student_id IN " +
//            "<foreach item='id' index='index' collection='studentIds' open='(' separator=',' close=')'>" +
//            "#{id}" +
//            "</foreach>" +
//            "</script>")
//    List<String> batchReadSchoolNamesByStudentIds(@Param("studentIds") List<Long> studentIds);
    @Select("<script>" +
            "SELECT t1.student_id, t2.`name` AS school_name " +
            "FROM student_read_school AS t1 " +
            "LEFT JOIN student_at_school AS t2 ON t1.reading_school_id = t2.id " +
            "WHERE t1.student_id IN " +
            "<foreach item='id' index='index' collection='studentIds' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<ScoreDataDetail> batchReadSchoolNamesByStudentIds(@Param("studentIds") List<Long> studentIds);
}
